home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigantic Games 2
/
Gigantic Games 2.iso
/
pc
/
_d_
/
dogfight!
/
sources.lha
/
DogFight!_1.0.cpp
next >
Wrap
C/C++ Source or Header
|
1994-05-21
|
43KB
|
1,035 lines
/*×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
##
## Filename: DogFight!
## Compiler: Maxon C++
##
##
## $HISTORY:
## Date Rev Comment
## 21 May 1994 | 01.22 | Converted to SAS/C
## 09 May 1994 | 01.21 | Changed header (oooh!), and am attempting to fix
## the crash bug by liberal use of the CacheClearU()
## function. So far, no success.
## 09 May 1994 | 00.00 | 18:08:02
##
## Old Revision list:
## v0.5 28-Feb-94 Changing input to direct keyboard read.
## v0.6 28-FEB-94 Added screenmode requester, alert for illegal
## number of players, info, WB startable.
## 01-Mar-94 Added menus; removed the need to have WB2.1
## by offering an ASL screenmode requester
## replacement (not ideal, but it works).
## Cosmetix: The Jets are now all erased and then
## all drawn, which prevents seeing the erase
## blocks when Jets fly through each other.
## v0.9b 10-Mar-94 Changed MUI a bit; added scores while pausing,
## changed color scheme; changed general speed
## of game. Changed game controls.
## v1.0 18-Mar-94 Reduced the frequency of crashes, though not
## eliminated. Added computer controlled Jets.
## v1.1 21-Mar-94 Took out scores page; put the ASL screenmode
## requester in the menu bar.
## v1.2 30-Mar-94 Added sound. Wata bitch.
## 17-Apr-94 Several small modifications. Think I finally
## solved the Big Bug. See the dox.
##
## ©1994 Apocalypse Productions
## Sean Russell
##
×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××*/
#define REVISION "1.22"
#define REVDATE "21/05/94"
#define REVTIME "14:20:00"
#define VERNUM 1
#define REVNUM 22
#define PROGRAM "DogFight!"
#define VERSION PROGRAM " " REVISION " (" REVDATE ")"
const char *VERSTAG = "$VER: " PROGRAM " " REVISION " (" REVDATE ")";
char *about_text = "\033c\033b" PROGRAM "\n\033n"
"\033i" REVISION " " REVDATE "\033n\n"
"\nBy\nSean E. Russell\n\n"
"DogFight! is a MUI application\n"
"MUI is © Stefan Stunz";
/********************************************************************
×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
ToDo/Bug list
(b) The colors are screwy if you're not using a PAL screen.
(b) It STILL crashes.
10 - Clean the code up.
11 - Playtesting
12 - Parachuters.
×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
*********************************************************************/
// keyboard.device OpenDevice opts
#define S_UNUM 0
#define S_FLAGS 0
/// "Includes"
// general includes
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <math.h>
#include <intuition/intuition.h>
#include <libraries/mathffp.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include <clib/mathffp_protos.h>
#include <clib/mathtrans_protos.h>
#include <clib/alib_protos.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>
#include <exec/types.h>
#include <exec/exec.h>
#include <exec/execbase.h>
#include <graphics/displayinfo.h>
#include <graphics/videocontrol.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <libraries/asl.h>
#include <libraries/mui.h>
#include <stdio.h>
#include <devices/keyboard.h>
#include <clib/exec_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/asl_protos.h>
#include <clib/muimaster_protos.h>
#include <proto/intuition.h>
#include <proto/mathffp.h>
#include <proto/gadtools.h>
#include <proto/mathtrans.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include <proto/asl.h>
#include <proto/muimaster.h>
#include "dogfight!_class9.h"
#include "dogfight!_1.0.h"
#include "sound.h"
///
/// "Global variables"
// shared library pointers
struct Library *GadToolsBase = NULL;
struct Library *MathTransBase = NULL;
struct Library *AslBase = NULL;
struct Library *MUIMasterBase = NULL;
// global variables available to this file
struct Screen *tankscreen1 = NULL; // the game screen
struct RastPort rport[2]; // rasterport array for doublebuffering
struct MsgPort *replyport = NULL; // for keyboard control
struct IOStdReq *iostdreq = NULL; // for keyboard.device
struct MsgPort *msgport = NULL; // for doublebuffering
struct ScreenBuffer *scbuf[] = // for doublebuffering
{
NULL,
NULL,
};
struct TagItem vctags[] =
{
VTAG_BORDERSPRITE_SET, TRUE,
TAG_DONE, 0,
};
struct ColorSpec colors[] = { // gamescreen colors
{0, 0, 0, 0},
{1, 15, 15, 15},
{2, 0, 0, 15},
{3, 15, 0, 0},
{4, 0, 15, 0},
{5, 15, 14, 0},
{6, 9, 9, 9},
{7, 0, 15, 0},
{-1, -1, -1, -1},
NULL,
};
struct NewMenu menu[] = { // gadtools menu
{NM_TITLE, "Project", 0, 0, 0, APTR(0)},
{NM_ITEM, "About", "?", 0, 0, APTR(ID_about)},
{NM_ITEM, NM_BARLABEL, 0, 0, 0, APTR(0)},
{NM_ITEM, "Screen...", "C", 0, 0, APTR(ID_screen)},
{NM_ITEM, "Save", "S", 0, 0, APTR(ID_save)},
{NM_ITEM, NM_BARLABEL, 0, 0, 0, APTR(0)},
{NM_ITEM, "Quit", "Q", 0, 0, APTR(MUIV_Application_ReturnID_Quit)},
{NM_END, NULL, 0, 0, 0, APTR(0)}};
UWORD *mbptr;
struct Window *mbwnd;
///
/// "computer(FIGHTER &player)"
/******************************************
×××××××××××××××××××××××××××××××××××××××××××
Computer controlled Jet
(at this point, only dumb)
returns: 1 for left
2 for right
3 for fire
0 for no action
×××××××××××××××××××××××××××××××××××××××××××
******************************************/
void computer(FIGHTER &p) {
long k;
k = lrand48() % 100;
if (k < 5) p.left();
if (k > 94) p.right();
if (k > 80) p.fire();
}
///
/// "evaluate(int buffer_element, int left, int right, int fire, int last_key_array, FIGHTER &player)"
/******************************************
×××××××××××××××××××××××××××××××××××××××××××
evaluate a keypress.
returns TRUE everytime a key is pressed.
×××××××××××××××××××××××××××××××××××××××××××
******************************************/
__inline void evaluate(int bf, int lt, int rt, int fr, int *lst, FIGHTER &p) {
if (buff[bf] & lt) {
if (!lst[0]) {
lst[0] = TRUE;
p.left();
}
}
else lst[0] = FALSE;
if (buff[bf] & rt) {
if (!lst[1]) {
lst[1] = TRUE;
p.right();
}
}
else lst[1] = FALSE;
if (buff[bf] & fr)
p.fire();
}
///
/// "int openscreen(bool request)"
/******************************************
×××××××××××××××××××××××××××××××××××××××××××
Opens the game screen and allocates
all screen-dependant variables.
If passed TRUE, requests a screen
size with either an ASL requester
or a MUI requester.
×××××××××××××××××××××××××××××××××××××××××××
******************************************/
int openscreen(BOOL req) {
/******************************************
If any screen stuff is open, close it.
******************************************/
if (mbwnd) CloseWindow(mbwnd);
if (scbuf[1]) FreeScreenBuffer(tankscreen1, scbuf[1]);
if (scbuf[0]) FreeScreenBuffer(tankscreen1, scbuf[0]);
if (tankscreen1) CloseScreen(tankscreen1);
ULONG dispid;
if (req) {
/******************************************
If they have WB2.1 or greater we can
use the ASL screenmode requester, which
provides graphiccard support.
Otherwise, we offer the user a choice
from 4 standard screens.
******************************************/
if (AslBase) {
struct ScreenModeRequester *request;
if (!(request = (struct ScreenModeRequester *)AllocAslRequestTags(
ASL_ScreenModeRequest,
ASLSM_InitialAutoScroll, FALSE,
ASLSM_InitialDisplayID, DBLPALHIRESFF_KEY,
ASLSM_InitialDisplayDepth, 3,
ASLSM_DoOverscanType, FALSE,
ASLSM_DoHeight, TRUE,
ASLSM_DoWidth, TRUE,
ASLSM_MinWidth, 320,
ASLSM_MinHeight, 200,
ASLSM_PropertyFlags, DIPF_IS_DBUFFER,
ASLSM_PropertyMask, DIPF_IS_DBUFFER,
TAG_DONE)))
return ER_ALLOCASL;
if (!(AslRequest((APTR)request, NULL)))
return ER_OPENASL;
dispid = request->sm_DisplayID;
scrn_width_MAX = request->sm_DisplayWidth;
scrn_height_MAX = request->sm_DisplayHeight;
FreeAslRequest((APTR)request);
}
else {
signed long choice;
int xres[] = {640, 320, 640};
int yres[] = {512, 200, 480};
int dispids[] = {DBLPALHIRESFF_KEY, LORES_KEY, DBLNTSCHIRES_KEY};
choice = MUI_Request(app, NULL, 0, "ScreenMode",
"_Lores NTSC|*_DBLPALHires|DBLNTSCHires",
"Since I can't find asl.library v39+ you only\n"
"have a choice from 4 screen modes. Lores is\n"
"320x200, DBLPALHires is 640x512, DBLNTSCHires\n"
"is 640x480");
dispid = dispids[choice];
scrn_width_MAX = xres[choice];
scrn_height_MAX = yres[choice];
}
}
else {
dispid = DBLPALHIRESFF_KEY;
scrn_width_MAX = 640;
scrn_height_MAX = 512;
}
scrn_left = 30;
scrn_right = scrn_width_MAX - 30;
scrn_top = 30;
scrn_bottom = scrn_height_MAX - 30;
/*****************************
We open the game screen
behind the workbench
******************************/
if (!(tankscreen1 = OpenScreenTags(NULL,
SA_DisplayID, dispid,
SA_Overscan, OSCAN_TEXT,
SA_Depth, 3,
SA_Width, scrn_width_MAX,
SA_Height, scrn_height_MAX,
SA_Behind, TRUE,
SA_Quiet, TRUE,
SA_VideoControl, vctags,
TAG_DONE)))
return ER_OS1;
int i;
for (i=0;i<8;i++)
SetRGB4(&(tankscreen1->ViewPort), i,
colors[i].Red,
colors[i].Green,
colors[i].Blue);
SetRast(&(tankscreen1->RastPort), 0);
if (!(mbwnd = OpenWindowTags( 0L,
WA_CustomScreen, tankscreen1,
WA_NoCareRefresh, TRUE,
WA_Backdrop, TRUE,
WA_Borderless, TRUE,
TAG_END )))
return ER_OPENMBWND;
SetPointer( mbwnd, mbptr, 0, 0, 0, 0 );
/******************************
Now we allocate screen
buffers for the double
buffering
*******************************/
if (!(scbuf[0] = AllocScreenBuffer(tankscreen1, NULL, SB_SCREEN_BITMAP)))
return ER_ASBS;
if (!(scbuf[1] = AllocScreenBuffer(tankscreen1, NULL, SB_COPY_BITMAP)))
return ER_ASBC;
rport[0].BitMap = scbuf[0]->sb_BitMap;
rport[1].BitMap = scbuf[1]->sb_BitMap;
return 0;
}
///
/// "int openall()"
/******************************************
×××××××××××××××××××××××××××××××××××××××××××
open all libraries, screens, apps, and
input devices.
returns 0 if successfull, otherwise the
error value (see DogFight!4.h)
×××××××××××××××××××××××××××××××××××××××××××
******************************************/
int openall() {
/*****************************************
Open libraries.
******************************************/
if (!(GadToolsBase = OpenLibrary((unsigned char *)"gadtools.library", (unsigned long)39)))
return ER_GTL;
if (!(MathBase = OpenLibrary((unsigned char *)"mathffp.library", (unsigned long)39)))
return ER_MATHFFP;
if (!(MathTransBase = OpenLibrary((unsigned char *)"mathtrans.library", (unsigned long)37)))
return ER_MATHTRANS;
if (!(MUIMasterBase = OpenLibrary((unsigned char *)MUIMASTER_NAME, (unsigned long)MUIMASTER_VMIN)))
return ER_MUIMAST;
if (!(AslBase = OpenLibrary((unsigned char *)"asl.library", (unsigned long)39)))
return ER_ASLBASE;
/****************************************
Generate MUI application
*****************************************/
app = ApplicationObject,
MUIA_Application_Title, "DogFight!",
MUIA_Application_Version, VERSION,
MUIA_Application_Copyright, "Apocalypse Productions © MCMXCIV",
MUIA_Application_Author, "Sean E. Russell",
MUIA_Application_Description, "Up to 4 player dogfight game",
MUIA_Application_Base, "DOGF",
MUIA_Application_Menu, menu,
SubWindow, WI_setup = WindowObject,
MUIA_Window_Title, "Prefs",
MUIA_Window_ID, MAKE_ID('P', 'R', 'F', 'S'),
WindowContents, VGroup,
Child, RG_main = RegisterGroup(pages),
MUIA_Register_Frame, TRUE,
Child, VGroup,
Child, CY_player[PLAYER1] = CycleObject,
MUIA_Cycle_Entries, control,
MUIA_ExportID, 8,
End,
Child, HGroup,
Child, RA_player[PLAYER1] = RadioObject,
MUIA_Radio_Entries, radbutts,
MUIA_ExportID, 1,
End,
Child, TextObject,
TextFrame,
MUIA_Background, MUII_ListBack,
MUIA_Text_Contents, controls[0],
End,
End,
End,
Child, VGroup,
Child, CY_player[PLAYER2] = CycleObject,
MUIA_Cycle_Entries, control,
MUIA_ExportID, 7,
End,
Child, HGroup,
Child, RA_player[PLAYER2] = RadioObject,
MUIA_Radio_Entries, radbutts,
MUIA_ExportID, 2,
End,
Child, TextObject,
TextFrame,
MUIA_Background, MUII_ListBack,
MUIA_Text_Contents, controls[1],
End,
End,
End,
Child, VGroup,
Child, CY_player[PLAYER3] = CycleObject,
MUIA_Cycle_Entries, control,
MUIA_ExportID, 9,
End,
Child, HGroup,
Child, RA_player[PLAYER3] = RadioObject,
MUIA_Radio_Entries, radbutts,
MUIA_ExportID, 3,
End,
Child, TextObject,
TextFrame,
MUIA_Background, MUII_ListBack,
MUIA_Text_Contents, controls[2],
End,
End,
End,
Child, VGroup,
Child, CY_player[PLAYER4] = CycleObject,
MUIA_Cycle_Entries, control,
MUIA_ExportID, 10,
End,
Child, HGroup,
Child, RA_player[PLAYER4] = RadioObject,
MUIA_Radio_Entries, radbutts,
MUIA_ExportID, 4,
End,
Child, TextObject,
TextFrame,
MUIA_Background, MUII_ListBack,
MUIA_Text_Contents, controls[3],
End,
End,
End,
End,
Child, VGroup,
Child, HGroup,
GroupFrameT("Global Options"),
MUIA_Group_SameHeight, TRUE,
Child, HVSpace,
Child, Label("Fast Game"),
Child, CH_speed = ImageObject,
ImageButtonFrame,
MUIA_InputMode, MUIV_InputMode_Toggle,
MUIA_Image_Spec, MUII_CheckMark,
MUIA_Image_FreeVert, TRUE,
MUIA_Selected, TRUE,
MUIA_Background, MUII_ButtonBack,
MUIA_ShowSelState, FALSE,
MUIA_ExportID, 5,
End,
Child, HVSpace,
Child, HVSpace,
Child, Label1("Safe Start"),
Child, CH_vuln = ImageObject,
ImageButtonFrame,
MUIA_InputMode, MUIV_InputMode_Toggle,
MUIA_Image_Spec, MUII_CheckMark,
MUIA_Image_FreeVert, TRUE,
MUIA_Selected, TRUE,
MUIA_Background, MUII_ButtonBack,
MUIA_ShowSelState, FALSE,
MUIA_ExportID, 6,
End,
Child, HVSpace,
End,
Child, HGroup,
Child, BU_go = KeyButton("Go!", 'g'),
Child, BU_save = KeyButton("Save", 's'),
Child, BU_quit = TextObject,
ButtonFrame,
MUIA_Text_Contents, "Quit",
MUIA_Text_PreParse, "\033c",
MUIA_Text_SetMax, FALSE,
MUIA_Text_HiChar, 'q',
MUIA_ControlChar, 'q',
MUIA_InputMode, MUIV_InputMode_RelVerify,
MUIA_Background, MUII_ButtonBack,
End,
End,
End,
End,
End,
End;
if (!app) return ER_APP;
/******************************************
Here's a messageport for the DBLBUFF
******************************************/
if (!(msgport = CreateMsgPort()))
return ER_DBMP;
/******************************
And create some rasterports
so we can draw on the
bitmaps
*******************************/
InitRastPort(&rport[0]);
InitRastPort(&rport[1]);
/******************************************
Call the OpenScreen routine
******************************************/
if (!( mbptr=(UWORD *)AllocVec(sizeof(WORD)*4,MEMF_CHIP)))
return ER_ALOCMBPTR;
/************************************
Open and initialize the keyboard
device.
*************************************/
if (!(replyport = CreateMsgPort()))
return ER_CMSGPORT;
if (!(iostdreq = (struct IOStdReq *)CreateIORequest(
replyport, sizeof(struct IOStdReq)
) ))
return ER_CSTDIO;
if (OpenDevice((unsigned char *)"keyboard.device", (unsigned long)S_UNUM,
(struct IORequest *)iostdreq, (unsigned long)S_FLAGS))
return ER_OKBD;
iostdreq->io_Command = KBD_READMATRIX;
iostdreq->io_Flags = IOF_QUICK;
iostdreq->io_Length = 16;
iostdreq->io_Data = buff;
return ER_none;
}
///
/// "error(int error_number)"
/******************************************
×××××××××××××××××××××××××××××××××××××××××××
Closes all open devices, screens,
objects, etc; frees all memory.
If e, outputs the appropriate
error message.
×××××××××××××××××××××××××××××××××××××××××××
******************************************/
void error(int e) {
if (iostdreq) {
if (iostdreq->io_Device)
CloseDevice((struct IORequest *)iostdreq);
DeleteIORequest(iostdreq);
}
if (replyport) DeleteMsgPort(replyport);
if (mbwnd) CloseWindow(mbwnd);
if (mbptr) FreeVec(mbptr);
if (scbuf[1]) FreeScreenBuffer(tankscreen1, scbuf[1]);
if (scbuf[0]) FreeScreenBuffer(tankscreen1, scbuf[0]);
if (tankscreen1) CloseScreen(tankscreen1);
if (msgport) DeleteMsgPort(msgport);
if (AslBase) CloseLibrary(AslBase);
if (app) MUI_DisposeObject(app);
if (MUIMasterBase) CloseLibrary(MUIMasterBase);
if (MathTransBase) CloseLibrary(MathTransBase);
if (MathBase) CloseLibrary((struct Library *)MathBase);
if (GadToolsBase) CloseLibrary(GadToolsBase);
closesound();
if (e) {
printf("ERROR: %s\n", ERRORS[e]);
exit(20);
}
exit(0);
}
///
/// "pause(struct RastPort *rp, Fighter *fighter_array)"
/******************************************
×××××××××××××××××××××××××××××××××××××××××××
Pauses the game
×××××××××××××××××××××××××××××××××××××××××××
******************************************/
void pause(struct RastPort *rp, FIGHTER *pl) {
BOOL paused = TRUE;
char scrs[50];
int i;
struct IntuiText scrstxt = {2, 0, JAM1, 0, 0, &topaz8, (unsigned char *)scrs, NULL};
scrstxt.FrontPen = 6;
sprintf(scrs, "Scores --");
PrintIText(rp, &scrstxt,
int((scrn_width_MAX - 120)/2),
int((scrn_height_MAX - 32)/2));
for (i=0;i<4;i++) {
if (pl[i].in_play) {
sprintf(scrs, "Player %d: %d", i+1, pl[i].killscore);
scrstxt.FrontPen = 6;
PrintIText(rp, &scrstxt,
int((scrn_width_MAX - 160)/2) - 1,
int((scrn_height_MAX - 32)/2) + ((i+1)*10) + 1 );
scrstxt.FrontPen = (unsigned char)(i+1);
PrintIText(rp, &scrstxt,
int((scrn_width_MAX - 160)/2),
int((scrn_height_MAX - 32)/2) + ((i+1)*10) );
}
}
while (paused) {
DoIO((struct IORequest *)iostdreq);
if (buff[3] & 1)
paused = FALSE;
WaitTOF();
}
SetAPen(rp, 0);
RectFill(rp,
int((scrn_width_MAX - 160)/2),
int((scrn_height_MAX - 32)/2),
int((scrn_width_MAX + 160)/2),
int((scrn_height_MAX + (i*15) + 32)/2)
);
}
///
/******************************************
×××××××××××××××××××××××××××××××××××××××××××
M A I N
×××××××××××××××××××××××××××××××××××××××××××
******************************************/
void main(int argc, char **argv) {
int err=0;
/****************************************
Open libraries, allocate screens, etc.
*****************************************/
if (err = openall())
error(err);
if (err = setupsound()) {
printf("ERROR %i: %s\n", err, SNDERRORS[err]);
error(0);
}
/**************************************
Attach buttons; setup general
MUI notification
***************************************/
DoMethod((Object *)WI_setup, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
DoMethod((Object *)BU_go, MUIM_Notify, MUIA_Pressed, FALSE,
app, 2, MUIM_Application_ReturnID, ID_gobutton);
DoMethod((Object *)BU_quit, MUIM_Notify, MUIA_Pressed, FALSE,
app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
DoMethod((Object *)BU_save, MUIM_Notify, MUIA_Pressed, FALSE,
app, 2, MUIM_Application_ReturnID, ID_save);
// Set up tab chain
DoMethod((Object *)WI_setup, MUIM_Window_SetCycleChain,
CH_speed, CH_vuln, BU_go, BU_save, BU_quit, NULL);
// Load application setup
DoMethod((Object *)app, MUIM_Application_Load, MUIV_Application_Load_ENV);
/****************************************
Open SetUp window, and wait until
they press a button.
*****************************************/
BOOL go_flag = FALSE;
BOOL running = TRUE;
BOOL exit = FALSE;
ULONG signal;
int i, numplay = 0;
ULONG perf[4];
ULONG cont[4];
set((Object *)WI_setup, MUIA_Window_Open, TRUE);
while (running) {
while((!go_flag) && (!exit)) {
switch (DoMethod((Object *)app, MUIM_Application_Input, &signal)) {
case MUIV_Application_ReturnID_Quit:
exit = TRUE;
running = FALSE;
go_flag = FALSE;
break;
case ID_gobutton:
go_flag = TRUE;
break;
case ID_save:
DoMethod((Object *)app,
MUIM_Application_Save, MUIV_Application_Save_ENVARC);
DoMethod((Object *)app,
MUIM_Application_Save, MUIV_Application_Save_ENV);
break;
case ID_about:
MUI_Request(app, WI_setup, 0, "About", "_Ok", about_text);
break;
case ID_screen:
if (err = openscreen(TRUE))
error(err);
break;
default:
break;
}
if (signal) Wait(signal);
}
numplay = 0;
for (i=0;i<4;i++) {
get((Object *)CY_player[i], MUIA_Cycle_Active, &(perf[i]));
get((Object *)RA_player[i], MUIA_Radio_Active, &(cont[i]));
if (perf[i])
numplay++;
}
if (numplay < 2) {
go_flag = FALSE;
MUI_Request(app, WI_setup, 0, "Ugh", "_Ok",
"\033cYou must activate at least\n2 players to have a dogfight!");
}
else running = FALSE;
}
if (!tankscreen1)
if (err = openscreen(FALSE))
error(err);
ULONG temp;
get((Object *)CH_vuln, MUIA_Selected, &temp);
vulnerability = (signed short)(!BOOL(temp));
get((Object *)CH_speed, MUIA_Selected, &temp);
game_speed = int(temp);
set((Object *)WI_setup, MUIA_Window_Open, FALSE);
set((Object *)app, MUIA_Application_Sleep, TRUE);
/**************************************
Initialize fighters from SetUp
window.
***************************************/
FIGHTER player[4];
int j=0;
for (i=0; i < 4; i++) {
player[i].shot.stop();
if (perf[i])
player[i].init(i, int(cont[i])+1);
else player[i].init(i, 0);
player[i].killscore = 0;
}
/**************************************
This is the main program loop.
***************************************/
int buffernum=0;
int p3last[2], p2last[2], p1last[2], p0last[2];
struct Message *msg = NULL;
ULONG sig = 0;
scbuf[buffernum]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort = msgport;
while (!exit) {
/**************************************
This is the actual dogfight loop.
***************************************/
ScreenToFront(tankscreen1);
ActivateWindow(mbwnd);
running = TRUE;
while (running) {
if (sig & (1<<msgport->mp_SigBit)) {
while (msg = GetMsg(msgport)) {
msg = NULL;
}
}
/**************************
Check user input
***************************/
DoIO((struct IORequest *)iostdreq);
if (perf[3] == 1)
evaluate(3, 32, 128, 64, p3last, player[3]);
else
computer(player[3]);
if (perf[2] == 1)
evaluate(5, 2, 8, 4, p2last, player[2]);
else
computer(player[2]);
if (perf[1] == 1)
evaluate(6, 32, 128, 64, p1last, player[1]);
else
computer(player[1]);
if (perf[0] == 1)
evaluate(6, 1, 4, 2, p0last, player[0]);
else
computer(player[0]);
if (buff[8] & 32) running = FALSE;
if (buff[3] & 2) pause(&rport[!buffernum], player);
/******************
End user input
*******************/
/******************************************
We erase all of the Jets at once...
******************************************/
for (i=0;i<4;i++) {
if (player[i].in_play) {
if (!player[i].alive)
player[i].resurect(i, int(cont[i])+1);
player[i].erase(&rport[buffernum]);
}
}
/******************************************
...and draw them on a "fresh" screen.
This takes a little longer, but jets
overlap nicely instead of blanking each
other.
******************************************/
for (i=0;i<4;i++) {
if (player[i].in_play) {
player[i].move(&(rport[buffernum]));
for (j=0;j<4;j++) {
if ((i!=j)&player[j].in_play)
if (player[i].collide(&(player[j].shot)))
player[j].killscore++;
}
}
}
CacheClearU();
scbuf[buffernum]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort = msgport;
while (!(ChangeScreenBuffer(tankscreen1, scbuf[buffernum]))) {
WaitTOF();
}
sig = Wait(1 << msgport->mp_SigBit);
buffernum = !buffernum;
}
/********************
End dogfight loop
*********************/
ScreenToBack(tankscreen1);
/*******************************
Allow players to change opts
********************************/
running = TRUE;
go_flag = FALSE;
set((Object *)app, MUIA_Application_Sleep, FALSE);
set((Object *)WI_setup, MUIA_Window_Open, TRUE);
while (running) {
while((!go_flag) && (!exit)) {
switch (DoMethod((Object *)app, MUIM_Application_Input, &signal)) {
case MUIV_Application_ReturnID_Quit:
exit = TRUE;
go_flag = FALSE;
running = FALSE;
break;
case ID_gobutton:
go_flag = TRUE;
break;
case ID_save:
DoMethod((Object *)app,
MUIM_Application_Save, MUIV_Application_Save_ENVARC);
DoMethod((Object *)app,
MUIM_Application_Save, MUIV_Application_Save_ENV);
break;
case ID_about:
MUI_Request(app, WI_setup, 0, "About", "_Ok", about_text);
break;
case ID_screen:
if (err = openscreen(TRUE))
error(err);
break;
default:
break;
}
if (signal) Wait(signal);
}
if (!exit) {
numplay = 0;
for (i=0;i<4;i++) {
get((Object *)RA_player[i], MUIA_Radio_Active, &cont[i]);
get((Object *)CY_player[i], MUIA_Cycle_Active, &perf[i]);
if (perf[i])
numplay++;
}
if (numplay < 2) {
go_flag = FALSE;
MUI_Request(app, WI_setup, 0, "Ugh", "_Ok",
"\033cYou must activate at least\n2 players to have a dogfight!");
}
else running = FALSE;
}
}
if (!exit) {
get((Object *)CH_vuln, MUIA_Selected, &temp);
vulnerability = (signed short)(!BOOL(temp));
get((Object *)CH_speed, MUIA_Selected, &temp);
game_speed = int(temp);
set((Object *)WI_setup, MUIA_Window_Open, FALSE);
set((Object *)app, MUIA_Application_Sleep, TRUE);
/************************
Clear the screens
*************************/
SetRast(&rport[0], 0);
SetRast(&rport[1], 0);
/************************
Re-init fighters for
a new game.
*************************/
for (i=0; i < 4; i++) {
if (perf[i])
player[i].init(i, (int)cont[i] + 1);
else player[i].init(i, 0);
player[i].killscore = 0;
}
}
}
/************************
End main program loop
*************************/
set((Object *)app, MUIA_Application_Sleep, FALSE);
set((Object *)WI_setup, MUIA_Window_Open, FALSE);
error(0);
}
/************************
End main()
*************************/